using System;
using PS.WebParts.Rollup.GridViewWebPart;

namespace PS.WebParts
{
    internal class GridViewToolPart
        : DataSourceToolPart<GridViewWebPart>
    {
        private string columnsID;

        public GridViewToolPart(GridViewWebPart owner)
            : base(owner, "Data GridView Properties")
        {
        }
        
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            builder.RegisterField(columnsID,  owner.ColumnString );
        }

        void button_Click(object sender, EventArgs e)
        {
            owner.GenerateColumns();
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            columnsID = builder.CreateToolText("Columns", "To edit Columns, click on the button below", "Edit Columns...");
            builder.CreateButton("Generate Columns", button_Click);
        }

        public override void ApplyChanges()
        {
            base.ApplyChanges();
            owner.ColumnString = builder.RetrieveValue(columnsID);
        }
    }
}
